<template>
    <!-- 优惠券列表 -->
        <van-coupon-list :coupons="couponlist" :chosen-coupon="chosenCoupon" :disabled-coupons="disabledCoupons"
            @change="onCouponChange" :show-exchange-bar="false" />
</template>

<script>

// 优惠券
const couponlist = ref([]);
const showList = ref(true);
const chosenCoupon = ref(-1);

onBeforeMount(() => {
    getCouponData()
})

const getCouponData = async () => {
    let result = await Api.CouponOrder({
        busid: LoginUser.id
    })

    if (result.code == 1) {
        result.data.forEach((item) => {
            couponlist.value.push({
                id: item.id,
                condition: '正在活动中',
                value: 0,
                name: item.coupon.title,
                startAt: item.coupon.createtimes,
                endAt: item.coupon.endtime,
                valueDesc: parseFloat(item.coupon.rate) * 100,
                unitDesc: '折',
                rate: item.coupon.rate
            })
        })
    }
}

const onCouponChange = (index) => {
    showList.value = false;
    chosenCoupon.value = index;
};

</script>

<style scoped>
/* 组件穿透样式写法 */
:deep(.van-field__control:read-only) {
    text-align: right;
}
</style>